package com.nsy.ovulatorymonitor;

import com.nsy.actionbartest.R;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;


public class TemperatureListActivity extends FragmentActivity implements
		TemperatureListFragment.Callbacks {

	/**
	 * Whether or not the activity is in two-pane mode, i.e. running on a tablet
	 * device.
	 */
	private boolean mTwoPane;
	
	private String mEmail;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		try
		{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_temperature_list);		

		if (findViewById(R.id.temperature_detail_container) != null) {
			// The detail container view will be present only in the
			// large-screen layouts (res/values-large and
			// res/values-sw600dp). If this view is present, then the
			// activity should be in two-pane mode.
			mTwoPane = true;

			// In two-pane mode, list items should be given the
			// 'activated' state when touched.
			((TemperatureListFragment) getSupportFragmentManager()
					.findFragmentById(R.id.temperature_list))
					.setActivateOnItemClick(true);
		}

		// TODO: If exposing deep links into your app, handle intents here.
		Intent intent=getIntent();
		mEmail = intent.getStringExtra(LoginActivity.EXTRA_EMAIL);
		Toast.makeText(getApplicationContext(), mEmail,
			     Toast.LENGTH_SHORT).show();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	
	
	/**
	 * Callback method from {@link TemperatureListFragment.Callbacks} indicating
	 * that the item with the given ID was selected.
	 */
	@Override
	public void onItemSelected(String id) {
		if (mTwoPane) {
			// In two-pane mode, show the detail view in this activity by
			// adding or replacing the detail fragment using a
			// fragment transaction.
			Bundle arguments = new Bundle();
			arguments.putString(TemperatureDetailFragment.ARG_ITEM_ID, id);
			TemperatureDetailFragment fragment = new TemperatureDetailFragment();
			fragment.setArguments(arguments);
			getSupportFragmentManager().beginTransaction()
					.replace(R.id.temperature_detail_container, fragment)
					.commit();

		} else {
			// In single-pane mode, simply start the detail activity
			// for the selected item ID.
			Intent detailIntent = new Intent(this,
					TemperatureDetailActivity.class);
			detailIntent.putExtra(TemperatureDetailFragment.ARG_ITEM_ID, id);
			startActivity(detailIntent);
		}
	}
	
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.main, menu);

        // Calling super after populating the menu is necessary here to ensure that the
        // action bar helpers have a chance to handle this event.
        return super.onCreateOptionsMenu(menu);
    }
	
	 @Override
	    public boolean onOptionsItemSelected(MenuItem item) {
	        switch (item.getItemId()) {
	            case android.R.id.home:
	                Toast.makeText(this, "Tapped home", Toast.LENGTH_SHORT).show();
	                break;

	            case R.id.menu_refresh:
	                Toast.makeText(this, "Fake refreshing...", Toast.LENGTH_SHORT).show();
	                Intent intent = new Intent(TemperatureListActivity.this, PeriodAddActivity.class);
		            startActivity(intent);
	                break;
	        }
	        return super.onOptionsItemSelected(item);
	    }
}
